package resource.i18n;

import java.util.List;

import cn.dreampie.common.util.json.Jsoner;
import cn.dreampie.route.annotation.API;
import cn.dreampie.route.annotation.GET;
import cn.dreampie.route.annotation.POST;
import frame.kit.MapKit;
import resource.ApiResource;
import resource.RestMsg;
import resource.i18n.model.I18nVersion;

/**
 * Created by hadong on 15-1-22.
 */
@API("/i18nversion")
public class i18nVersionResource extends ApiResource {

	@GET
	public List<I18nVersion> listAllI18nVersion() {
		return I18nVersion.dao.findAll();
	}

	@GET("/id/:id")
	public I18nVersion findI18nVersionById(int id) {
		return I18nVersion.dao.findFirstBy("id=?", id);
	}

	@POST("/add")
	public RestMsg addI18nVersion() {
		I18nVersion i18nVersion = Jsoner.toObject(Jsoner.toJSON(MapKit.params2Map(getParams())), I18nVersion.class);
		i18nVersion.save();
		return new RestMsg();
	}

	@POST("/update/:id")
	public RestMsg updateI18nVersion(Integer id) {
		I18nVersion i18nVersion = Jsoner.toObject(Jsoner.toJSON(MapKit.params2Map(getParams())), I18nVersion.class);
		I18nVersion old_i18nVersion = I18nVersion.dao.findFirstBy("id=?", id);
		if (null == old_i18nVersion) {
			return new RestMsg(500, "this id is not correct!");
		}
		old_i18nVersion.setAttrs(i18nVersion).update();
		return new RestMsg();
	}

	@GET("/delete/:id")
	public RestMsg deleteI18nVersion(int id) {
		I18nVersion.dao.deleteBy("id=?", id);
		return new RestMsg();
	}
}
